//
//  ThreadCache.h
//  ConcurrentMemoryPool
//
//  Created by 张木林 on 5/3/25.
//
#pragma once
#include"Common.hpp"

class ThreadCache
{
public:
    //申请和释放内存对象
    void* Allocate(size_t size);
    void Deallocate(void* ptr,size_t size);
    
    //从中心缓存获取对象
    void* FetchFromCentralCache(size_t index,size_t size);
    
    //释放对象时，链表过长时，回收内存回到中心链表
    void ListTooLong(FreeList& list,size_t size);
    
    
private:
    FreeList _freeLists[NFREELIST];
};


//下面这个windows写法
//static __declspec(thread) ThreadCache* pTLSThreadCache = nullptr;
static thread_local ThreadCache* pTLSThreadCache =  nullptr;
